

import { Component, OnInit, ViewChild } from '@angular/core';
import {
  PagedResultDto, ClassInfoOutput, PagerSearchInput, HttpService, BaseComponentConfig,
  CustomNavigation, KeyValueOutput, SearchValue
} from '../../..';
import { Router, Route, ActivatedRoute } from "@angular/router";
import { NzMessageService, NzNotificationService } from 'ng-zorro-antd';
import { MyeditorComponent } from '../../myeditor/myeditor.component';
@Component({
  selector: 'app-feedbace-edit',
  templateUrl: './feedbace-edit.component.html',
  styleUrls: ['./feedbace-edit.component.scss']
})
export class FeedbaceEditComponent implements OnInit {
  @ViewChild(MyeditorComponent) MyeditorComponent: MyeditorComponent;
  feedtype: any;
  fwbBjq: any;
  feedtypeValue: "";
  id;
  feedId;
  usertype;
  constructor(private http: HttpService, private _message: NzMessageService, private router: Router, private route: ActivatedRoute) {

  }
  async ngOnInit() {
    this.usertype = sessionStorage.getItem('userRoleType'); // 身份
    this.route.queryParams.subscribe(
      d => this.feedId = (d['feedId']));
    this.feedtype = [
      { "name": "使用体验反馈", "value": "使用体验反馈" },
      { "name": "软件问题反馈", "value": "软件问题反馈" },
      { "name": "建议优化反馈", "value": "建议优化反馈" },
    ];
    const data = await this.http.get<any>("FeedbackInformationService/GetInformation?Id=" + this.feedId);
    this.id = data.id;
    this.feedtypeValue = data.feedbackType;
    this.fwbBjq = data.feedbackInformationName;
    if (this.MyeditorComponent) {
      this.MyeditorComponent.setElement(this.fwbBjq);
    }
  }

  keyupHandler(event) {
    this.fwbBjq = event;
  }
  resultFh() {
    this.router.navigate(['app/feedIndex/feedback']);
  }
  async saveFeed() {
    if (this.feedtypeValue === undefined) {
      this._message.warning("请选择反馈类型");
    } else if (this.fwbBjq === undefined) {
      this._message.warning("请填写反馈信息");
    } else {
      const data = { "id": this.feedId, "feedbackType": this.feedtypeValue, "feedbackInformationName": this.fwbBjq };
      try {
        this.http.post<any>("FeedbackInformationService/UpdateInformation", data);
        this._message.success("修改成功");
        this.router.navigate(['app/feedIndex/feedback']);
      } catch (error) {
        this._message.error("修改反馈信息失败");
      }
    }
  }


}
